<template>
  <el-button size="large" type="primary" @click="editGroupDialog = true">修改</el-button>
  <el-dialog v-model="editGroupDialog" title="修改题组" width="350px">
    <el-form :model="form" label-width="80px">
      <el-form-item label="题组名称" prop="groupName">
        <el-input v-model="form.groupName"></el-input>
      </el-form-item>
      <el-form-item label="题组类型" prop="questionTypeId">
        <el-select v-model="form.questionTypeId" placeholder="请选择题组类型">
          <el-option v-for="(type,index) in types" :key="index" :label="type.typeName"
                     :value="type.questionTypeId"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input v-model="form.remark" :rows="2" type="textarea" placeholder="请输入备注"/>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="editGroupDialog = false">取消</el-button>
        <el-button type="primary" @click="doSubmit" :loading="loading">确认</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>
import { defineProps, inject, reactive, ref } from 'vue'
import { ElMessage } from 'element-plus'
import { editGroup, typeList } from '@/api/admin'

const props = defineProps<{ data: any }>()
const reload: any = inject('reload')
const loading = ref<boolean>(false)
const editGroupDialog = ref<boolean>(false)
const form = reactive({
  questionGroupId: props.data.questionGroupId,
  groupName: props.data.groupName,
  questionTypeId: props.data.questionTypeId,
  remark: props.data.remark,
  questionTotal: props.data.questionTotal
})
const doSubmit = () => {
  loading.value = true
  editGroup(form).then(() => {
    ElMessage.success('修改成功')
    editGroupDialog.value = false
    reload()
  }).finally(() => {
    loading.value = false
  })
}
const types = ref(null)
typeList().then(resp => {
  types.value = resp.data.data
})
</script>

<style scoped>

</style>
